<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\api\model\user\UserPersonAuth as UserPersonAuthModel;

/**
 * 个人认证接口
 */
class Userpersonauth extends Api
{
    protected $noNeedRight = ['*'];


    //提交认证
    public function add()
    {

        $person_auth = \app\api\model\user\UserCompanyAuth::get(['user_id'=>$this->auth->id]);
        if ($person_auth){
            $this->error('已是单位会员');
        }

        $model = new UserPersonAuthModel();

        $info = UserPersonAuthModel::get(['user_id'=>$this->auth->id]);
        /*if ($info){
            $this->error('已是个人会员');
        }*/

        $data = [
            'user_id'=>$this->auth->id,
            'headshot'=>input('headshot',''),
            'gender'=>input('gender',0),
            'birthday'=>input('birthday',''),
            'birthplace'=>input('birthplace',''),
            'city'=>input('city',''),
            'education'=>input('education',''),
            'job'=>input('job',''),
            'hobby'=>input('hobby',''),
            'phone'=>input('phone',''),
            'personal_intro'=>input('personal_intro',''),
            'status'=>1
        ];
        //if (empty($data['headshot']))$this->error('请上传形象照');
        //if (empty($data['birthday']))$this->error('请选择出生日期');
        if (empty($data['birthplace']))$this->error('请输入籍贯');
        if (empty($data['city']))$this->error('请输入现居城市');
        //if (empty($data['education']))$this->error('请输入教育');
        //if (empty($data['job']))$this->error('请输入职业');
        //if (empty($data['hobby']))$this->error('请输入爱好');
        //if (empty($data['email']))$this->error('请输入邮箱');
        if (empty($data['personal_intro']))$this->error('请输入个人介绍');

        if (!$info){
            $res = $model->save($data);
        } else {
            $res = $model->save($data,['id'=>$info['id']]);
        }
        $user = \app\admin\model\User::get($model->user_id);
        $user->headshot = $model->headshot;
        $user->gender = $model->gender;
        $user->birthday = $model->birthday;
        $user->birthplace = $model->birthplace;
        $user->city = $model->city;
        $user->education = $model->education;
        $user->job = $model->job;
        $user->hobby = $model->hobby;
        $user->phone = $model->phone;
        $user->personal_intro = $model->personal_intro;
        $user->person_auth = 1;
        /*if ($user->auth_status==2){
            $user->level_type = 1;
            $user->level = 1;
        }*/
        $user->save();
        $this->success('提交成功',$res);
    }


    //认证信息
    public function info()
    {
        $info = UserPersonAuthModel::get(['user_id'=>$this->auth->id]);
        $this->success('',$info);
    }
}